home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d13 / ptv2n1.arc / TEST.PAS < prev    next >
Pascal/Delphi Source File  |  1991-03-26  |  1KB  |  46 lines

  1. program Test;
  2.  
  3. { A simple program to illustrate the usage of the stack objects }
  4.  
  5. uses BaseObj,Stacks;
  6.  
  7. type TestObjPtr = ^TestObj;
  8.      TestObj = object(Base)            { Just a simple object }
  9.        Contents: string;
  10.        constructor Init(S: string);
  11.        procedure Display;
  12.        end;
  13.  
  14. constructor TestObj.Init(S: string);
  15.   { Create a new test object }
  16.   begin
  17.   Contents := S
  18.   end;
  19.  
  20. procedure TestObj.Display;
  21.   { Display the contents of a test object }
  22.   begin
  23.   writeln(Contents);
  24.   end;
  25.  
  26. var Ch: char;
  27.     TestStack: Stack;                  { This is the error!!! }
  28.     TempTestObj: TestObjPtr;
  29.  
  30. begin
  31. TestStack.Init;                        { Create the stack object }
  32.  
  33. for Ch := 'A' to 'E' do                { Put some objects on stack }
  34.   begin
  35.   new(TempTestObj,Init(Ch));           { Create a new TestObj  }
  36.   TestStack.Push(TempTestObj^);        { Push it on stack }
  37.   dispose(TempTestObj,Done)            { Destroy the TestObj again }
  38.   end;
  39.  
  40. while not TestStack.Empty do           { Show what's on the stack }
  41.   begin
  42.   TempTestObj := TestObjPtr(TestStack.Pop);
  43.   TempTestObj^.Display
  44.   end
  45. end.
  46.